package football.haha.com.footballtv.activity;

import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import football.haha.com.footballtv.R;
import football.haha.com.footballtv.utils.ActivityUtils;
import football.haha.com.footballtv.utils.Tools;

/**
 * Created by oo on 2017/10/8.
 */

public class BuySingleMealActivity extends BaseActivity {

    @Bind(R.id.tv_month)
    TextView tvMonth;
    @Bind(R.id.tv_price)
    TextView tvPrice;
    @Bind(R.id.btn_sigle)
    FrameLayout btnSigle;
    @Bind(R.id.btn_meal)
    FrameLayout btnMeal;
    @Bind(R.id.rl_main)
    RelativeLayout rlMain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_buy_single_meal);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.btn_sigle, R.id.btn_meal})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_sigle:
                showAgreement();
                break;
            case R.id.btn_meal:
                ActivityUtils.gotoActivity(this, BuyMealActivity.class);
                break;
        }
    }

    public void showAgreement() {
        final Dialog singeLeftRightTipDialog = new Dialog(this, R.style.MyDialog);
        singeLeftRightTipDialog.setContentView(R.layout.dialog_agreement);

        FrameLayout left = (FrameLayout) singeLeftRightTipDialog.findViewById(R.id.fl_buy);
        left.requestFocus();
        final CheckBox cbAgreement = (CheckBox) singeLeftRightTipDialog.findViewById(R.id.cb_agreement);
        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (cbAgreement.isChecked()) {
                    if (singeLeftRightTipDialog != null) {
                        singeLeftRightTipDialog.dismiss();
                    }
                    showDialogTip("恭喜你：\n订购成功，立即观看直播吧！", "看直播","取消");
                } else {
                    showToast("请先同意协议");
                }
            }
        });

        FrameLayout right = (FrameLayout) singeLeftRightTipDialog.findViewById(R.id.fl_cancel);
        right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (singeLeftRightTipDialog != null) {
                    singeLeftRightTipDialog.dismiss();
                }
                showDialogTip("抱歉，购买失败，请检查网络或咨询运营商","重新购买","取消");
            }
        });

        RelativeLayout warp = (RelativeLayout) singeLeftRightTipDialog.findViewById(R.id.fl_dialog);
        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(Tools.getDisplayWidth(this), Tools.getDisplayHeight(this));
        warp.setLayoutParams(lp);

        singeLeftRightTipDialog.show();
    }

}
